package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/5/13 11:38
 * @Version 1.0
 */
@Controller
public class ItemController {

    @Autowired
    private ItemFeignClient itemFeignClient;

    /**
     * 商品详情页面控制
     * @param skuId
     * @param model
     * @return
     */
    @GetMapping("{skuId}.html")
    public String skuItem(@PathVariable Long skuId, Model model){
        //  调用远程方法获取数据，并保存.
        Result<Map> result = itemFeignClient.getItem(skuId);
        model.addAllAttributes(result.getData());
        //  返回页面
        return "item/item";
    }

}
